<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>鼠标跟随</title>
    <style>
        img {
            width: 40px;
            height: auto;

            position: fixed;
            left: 0;
            top: 0;
        }
    </style>
</head>
<body>
<img src="/images/a.png" alt="">
<script>
    //获取元素
    var Img = document.querySelector('img')

    //给document绑定一个鼠标移动事件
    document.onmousemove = function (e) {
        //拿到光标相对于窗口的坐标定位
        var x = e.clientX
        var y = e.clientY

        //将e.clientX和e.clientY赋值给img标签的left和top样式
        Img.style.left = x + 'px'
        Img.style.top = y + 'px'
        console.log(x, y)
    }

</script>
</body>
</html>